#ifndef WIDGET_H
#define WIDGET_H

#include <QObject>
#include <QDebug>
#include <QAudioDeviceInfo>
#include <QAudioFormat>
#include <QAudioInput>
#include <QThread>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QTimer>
#include <QEventLoop>

#include <handleaudio.h>

class DcAudio : public QObject
{
    Q_OBJECT
public:
    DcAudio();
    ~DcAudio();
    QIODevice * qio;
    QAudioInput* audio;
    QAudioFormat format;
    HandleAudio *handle_recording_stream;
    QThread net_thread;

    void startRecord();
    const char *getResultAfter(int t);
    QAudioFormat * setRecord();
    const char *createSessionID();
    QString GetRecordFromAudio();
    bool deleteSession();
    void sendPutToServer();

private:
    QByteArray session_id;
    QString prefix_path = "http://192.168.31.186:8321/";
    QByteArray buffer;
    QByteArray buffer_total;

signals:
    void signalCanPost(const QByteArray &qba);

public slots:
    void slotReadStream();
    const char *getResult();

};

#endif // WIDGET_H
